/*
*/

#include "timer.h"

#include "display.h"
#include "event.h"

void Delay(u32 ms){
    ms+=clock;
    while(clock<ms){
	__WFI();
	Display();
    }
}

void InitTimer(void){
    //Init SysTick Base time to 1 ms.
    SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK);	//HCLK as SysTick source
    SysTick_SetReload(72000);				//1000Hz
    SysTick_ITConfig(ENABLE);				//Enable SysTick Int
    SysTick_CounterCmd(SysTick_Counter_Enable);
}

void SysTickHandler(void){
    ++clock;
}

u8 TimeOut(u32 time,u32 out){
    return time&&(clock-time)>=out;
}

u32 Timer(void){
    return clock?clock:1;
}
